﻿<Controls:MetroWindow x:Class="Shoozla.FolderExplorerView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:behaviours="clr-namespace:MahApps.Metro.Behaviours;assembly=MahApps.Metro" 
        xmlns:effect="clr-namespace:GrayscaleEffect;assembly=GrayscaleEffect"
        xmlns:s="clr-namespace:Shoozla"
        xmlns:sv="clr-namespace:Shoozla.View"
        xmlns:svm="clr-namespace:Shoozla.ViewModel"   
        AllowDrop="True"
        Title="Folder selection" Height="450" Width="400" ShowWindowCommands="False" ShowInTaskbar="False" Topmost="False" WindowStartupLocation="CenterOwner" UseLayoutRounding="True" AllowsTransparency="False" ShowIconOnTitleBar="False" ShowTitleBar="False"  DragEnter="MetroWindow_DragEnter" DragLeave="MetroWindow_DragLeave" DragOver="MetroWindow_DragOver" DragDrop.Drop="MetroWindow_Drop">        
    <i:Interaction.Behaviors>
        <behaviours:BorderlessWindowBehavior ResizeWithGrip="False" AutoSizeToContent="False" />
    </i:Interaction.Behaviors>
    
    <DockPanel>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="30"/>
            </Grid.RowDefinitions>
            <Button Grid.Row="0" Margin="4" Content="select root folder" Command="{Binding Path=CmdOpenFolderDialog}" />
            
            <TreeView x:Name="foldersTree" Grid.Row="1" BorderBrush="{DynamicResource HighlightBrush}" BorderThickness="0 1 1 0" >
            <TreeView.Resources>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="Foreground" Value="{DynamicResource BlackBrush}" />
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="VerticalContentAlignment" Value="Center" />
                    <Setter Property="MinHeight" Value="25" />
                    <Setter Property="Margin" Value="0,0,0,0" />
                    <Setter Property="IsTabStop" Value="False" />
                    <Setter Property="Border.BorderBrush" Value="{DynamicResource Grey3}" />
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate DataType="ContentPresenter">           
                                <Border x:Name="Bd" SnapsToDevicePixels="true">                                   
                                    <StackPanel  Orientation="Horizontal" Height="20">
                                        <CheckBox Margin="3,3,0,0" Name="folderCB"  IsChecked="False" Checked="folder_Checked"  Unchecked="folder_UnChecked"  Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                            AncestorType={x:Type TreeViewItem}}}"/>
                                        
                                        <TextBlock Text="{Binding}" Margin="3,0" />
                                    </StackPanel>      
                                </Border>
                                <DataTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="Bd" Property="Background">
                                            <Setter.Value>
                                                <SolidColorBrush Color="{DynamicResource AccentColor3}" />
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                        AncestorType={x:Type TreeViewItem}}, Path=(s:TreeViewItemProps.IsSelected)}" Value="True">
                                        <Setter TargetName="folderCB" Property="IsChecked" Value="True" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                        AncestorType={x:Type TreeViewItem}}, Path=(s:TreeViewItemProps.IsSelected)}" Value="False">
                                        <Setter TargetName="folderCB" Property="IsChecked" Value="False" />
                                    </DataTrigger>

                                     <!--<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                        AncestorType={x:Type TreeViewItem}}, Path=(s:TreeViewItemProps.IsRootLevel)}" Value="True">
                                        <Setter TargetName="img" Property="Source" Value="/Shoozla;component/Images/folder.png" />
                                    </DataTrigger>

                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                        AncestorType={x:Type TreeViewItem}}, Path=(s:TreeViewItemProps.IsRootLevel)}" Value="False">
                                        <Setter TargetName="img" Property="Source" Value="/Shoozla;component/Images/folder.png" />
                                    </DataTrigger>
                                    
                                    <DataTrigger Binding="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent}}" Value="True">
                                        <Setter TargetName="Bd" Property="BorderBrush" Value="#FF143c65" />
                                        <Setter Property="Background" TargetName="Bd" Value="{DynamicResource AccentColorBrush}"></Setter>
                                    </DataTrigger>-->
                                
                                </DataTemplate.Triggers>
                            </DataTemplate>                                          
                        </Setter.Value>
                    </Setter>

                </Style>
            </TreeView.Resources>
        </TreeView>
            <TextBlock Grid.Row="1" Margin="0,50,0,0" Width="160" TextWrapping="WrapWithOverflow"  HorizontalAlignment="Center" FontSize="12" FontStyle="Italic"  Background="Transparent" Visibility="{Binding ShowHint, Converter={StaticResource boolToVis}}" Text="No root folder selected, click on the button or drag and drop a folder" />
            <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,5,0" VerticalAlignment="Center">
            <Button Content="Cancel" Command="{Binding Path=CmdCancel}" Height="23" Width="50" Margin="5,0,0,5" IsDefault="True">
            </Button>
            <Button Content="OK" Command="{Binding Path=CmdApply}" ToolTip="Select the checked folders as Mp3 source" Height="23" Width="50" Margin="5,0,0,5" IsDefault="True" >
            </Button>
            </StackPanel>
        </Grid>
    </DockPanel>
</Controls:MetroWindow>
